package edu.sctu.alex.June.day20150607;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

/**
 * Created by user03 on 2015/6/7.
 */
public class ThreadTest implements Runnable {

    /**
     *
     * 计时器的尝试实现
     */

        @Override
        public void run() {
            //输出现在的时间
            Date date = new Date();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            System.out.println("Now Time:" + simpleDateFormat.format(date));

            //进行计时处理
            Scanner in  =  new Scanner(System.in);
            System.out.println("请输入你想要的计时时间（单位：秒）：");
            int s =in.nextInt();

            for (int i =1; i <s+1 ; i++) {
                System.out.println("已经过去："+i+"秒");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }

        }
}
